<?php
/**
 * Form Plugin (mail component): sends a mail with form contents
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Esther Brunner <wikidesign@gmail.com>  
 */
 
if (!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/');
if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
if (!defined('FORM_EMPTY')) define('FORM_EMPTY', '                    ');
if (!defined('FORM_HR')) define ('FORM_HR', '----------');

require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/mail.php');

$to      = stripctl($_REQUEST['to']);
$cc      = stripctl($_REQUEST['cc']);
$bcc     = stripctl($_REQUEST['bcc']);
$subject = stripctl($_REQUEST['subject']);
$from    = stripctl($_REQUEST['name']).' <'.stripctl($_REQUEST['mail']).'>';

$body  = '';
foreach ($_REQUEST as $key => $data){
  // ignore DokuWiki internal stuff
  if ((substr($key, 0, 2) === 'DW')
    || (substr($key, 0, 5) === 'DOKU_')
    || (substr($key, 0, 8) === 'DokuWiki'))
    continue;
    
  // ignore recipients and subject (it's already there)
  if (in_array($key, array('to', 'cc', 'bcc', 'subject'))) continue;
  
  if (strpos($data, DOKU_LF) !== false){
    $body .= $key.':'.DOKU_LF.FORM_HR.DOKU_LF.$data.DOKU_LF.FORM_HR.DOKU_LF;
  } else {
    $body .= substr($key.':'.FORM_EMPTY, 0, 20).$data.DOKU_LF;
  }
}

// send the mail
mail_send($to, $subject, $body, $from, $cc, $bcc);

// restore some DokuWiki parameters and go to a thanks page
$_REQUEST['do'] = $_REQUEST['DOKU_DO'];
$_REQUEST['id'] = $_REQUEST['DOKU_ID'];
header('Location: '.wl($_REQUEST['id']));
 
//Setup VIM: ex: et ts=4 enc=utf-8 :
